<?php

namespace admin\controller;

use admin\model\TargetModel;

class TargetController extends Controller{
    private $target;

    public function __construct(){
        $this->target = new TargetModel();
    }
    /**
     * 返回管理标签管理界面
     */
    public function getTargetAll(){
        return $this->view('manageTarget');
    }
    //查询所有的信息以 JSON 形式返回
    public function getTargetsJson($params){
        $data = $this->target->getTargetAll($params);
        $count_data = $this->target->getTargetCount(array('target'=>$params['target']));
        $data_json = [];
        $data_json['code'] = 0;
        $data_json['msg'] = '';
        $data_json['count'] = $count_data['count'];
        $data_json['data'] = $data;
        return json_encode($data_json);
    }
    /**
     * 更新标签
     */
    public function editTarget($params){
        $data = $this->target->updateTarger($params);
        return json_encode($data);
    }
    /**
     * 隐藏标签
     */
    public function hideTarget($params){
        $data = $this->target->hideTarget($params);  //操作数据库并返回状态嘛
        return json_encode($data);      //返回给前端 ajax 
    }
    /**
     * 删除标签
     */
    public function delTarget($params){
        $data = $this->target->delTarget($params);  //操作数据库并返回状态嘛
        return json_encode($data);      //返回给前端 ajax 
    }


}